package com.hspedu.exit_;

/**
 * @author DL5O
 * @version 1.0
 */
public class ThreadExitTest_ {
    public static void main(String[] args) throws InterruptedException {
        Test test = new Test();
        test.start();

        Thread.sleep(10*1000);//休眠10秒后，是线程结束
        test.setLoop(false);
    }
}
class Test extends Thread{
    private boolean loop = true;
    private int cnt = 0;
    @Override
    public void run() {
        while(loop){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Test 执行中" + (++cnt));
        }
        System.out.println("Test 运行结束");
    }

    public boolean isLoop() {
        return loop;
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }

    public int getCnt() {
        return cnt;
    }

    public void setCnt(int cnt) {
        this.cnt = cnt;
    }
}
